//
//  MTRootViewController.m
//  YuchBox
//
//  Created by Ivan on 11-9-29.
//  Copyright 2011年 __MyCompanyName__. All rights reserved.
//

#import "MTRootViewController.h"
#import "./YuchBox/LayoutParam.h"

@implementation MTRootViewController
@synthesize ivanTabBar = _ivanTabBar;
//@synthesize ivanTabBarController = _ivanTabBarController;
@synthesize navigationController = _navigationController;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)dealloc
{
    [_ivanTabBar release];
    
    [super dealloc];
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    // check environment
    [DataSource checkRunTimeEnvironment];
    
    // TEST
//    MTEmailViewController *emailViewController = [[MTEmailViewController alloc] init];
//    UINavigationController *navg = [[UINavigationController alloc] initWithRootViewController:emailViewController];
//    [self setNavigationController:navg];
//    [self.view addSubview:self.navigationController.view];
    //~TEST
    

    // init mainview
    MTEmailViewController *controller1 = [[MTEmailViewController alloc] initWithNibName:@"MTEmailViewController" bundle:nil];
    NSMutableDictionary *controllerDict1 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"message.png", @"image", controller1, @"viewController", nil];
    [controller1 release];
    //NSLog(@"@2 ctrl %d, dict %d\n", [controller1 retainCount], [controllerDict1 retainCount]);

    // init msgview
    MTMainViewController *controller2 = [[MTMainViewController alloc] initWithNibName:@"MTMainViewController" bundle:nil];
    //controller2.view.backgroundColor = [UIColor redColor];
    NSMutableDictionary *controllerDict2 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"chat.png", @"image", controller2, @"viewController", nil];
    [controller2 release];
    
    MTMsgViewController *controller3 = [[MTMsgViewController alloc] initWithNibName:@"MTMsgViewController" bundle:nil];
    NSMutableDictionary *controllerDict3 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"squares.png", @"image", controller3, @"viewController", nil];
    [controller3 release];

    MTMsgViewController *controller4 = [[MTMsgViewController alloc] initWithNibName:@"MTMsgViewController" bundle:nil];
    NSMutableDictionary *controllerDict4 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"user.png", @"image", controller4, @"viewController", nil];
    [controller4 release];

    MTMsgViewController *controller5 = [[MTMsgViewController alloc] initWithNibName:@"MTMsgViewController" bundle:nil];
    NSMutableDictionary *controllerDict5 = [[NSMutableDictionary alloc] initWithObjectsAndKeys:@"more.png", @"image", controller5, @"viewController", nil];
    [controller5 release];
    
    NSMutableArray *controllerArray = [[NSMutableArray alloc] initWithObjects:controllerDict1,controllerDict2,controllerDict3,controllerDict4,controllerDict5, nil];
    
    [controllerDict1 release];
    [controllerDict2 release];
    [controllerDict3 release];
    [controllerDict4 release];
    [controllerDict5 release];
   // self.ivanTabBar.items = controllerArray;

//    _ivanTabBar = [[IvanTabBar alloc] initWithItemCount:[controllerArray count] 
//                                                  Items:controllerArray 
//                                 BackgroudImageFileName:@"tabBarBackgroud.png" 
//                                        AutoSizeByImage:NO 
//                                                BarSize:CGSizeMake(DEVICE_WIDTH, TOOLBAR_HEIGHT)
//                                     ArrowImageFileName:@"arrow2.png"
//                                                Delegate:self];
    [controllerArray release];
    
//    UIViewController *ivanBarController = [[UIViewController alloc] init];
//
//    [ivanBarController.view addSubview:_ivanTabBar];
//    [self setIvanTabBarController:ivanBarController];
//    
//    UINavigationController *navg = [[UINavigationController alloc] initWithRootViewController:self.ivanTabBarController];
//    [self setNavigationController:navg];
    
    [self.view addSubview:_ivanTabBar];
   //  NSLog(@"@5 ctrl %d, dict %d, array %d\n", [controller1 retainCount], [controllerDict1 retainCount], [controllerArray retainCount]);
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}



@end
